﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PdfLibrary
{
    public class PdfDictionaryTypeResolver
    {
        public static Dictionary<string, Type> PdfTypeResolver = new Dictionary<string, Type>()
        {
            {"Catalog", typeof(IPdfDocumentCatalog)},
            {"Pages", typeof(IPdfPageTreeNode)},
            {"Page", typeof(IPdfPageObject)},
            {"Font", typeof(IPdfFont)},
        };

        public static Type Resolve(PdfDictionary dictionaryObject)
        {
            IPdfObject value;
            
            if(!dictionaryObject.TryGetValue("Type", out value) || !(value is PdfName))
                return null;

            var pdfType = ((PdfName)value).Value;

            Type result = null;
            PdfTypeResolver.TryGetValue(pdfType, out result);

            return result;
        }
    }
}
